﻿@model NCP.Model.GroupPurchase
@{
    ViewData["Title"] = "集采药品信息";
}
<style>
    /*滚动条样式*/
    .profile_con::-webkit-scrollbar {
        /*滚动条整体样式*/
        width: 10px; /*高宽分别对应横竖滚动条的尺寸*/
        height: 1px;
    }

    .profile_con::-webkit-scrollbar-thumb {
        /*滚动条里面小方块*/
        border-radius: 5px;
        background: #cccccc;
    }

    .profile_con::-webkit-scrollbar-track {
        /*滚动条里面轨道*/
        border-radius: 5px;
        background: #ffffff;
    }
</style>
<form class="layui-card layui-form" lay-filter="layuiadmin-form-list" id="dtFrm">
    <div class="layui-card-header" style="padding-bottom:15px;padding-top:15px;">
        <span style="margin-left:10px;margin-right:100px;font-size:large;font-weight:600;">@Model.Name [@Model.Code]</span>
        <button class="layui-btn" type="button" onclick="doSave()">
            保存
        </button>
        <button class="layui-btn layui-btn-danger" type="button" onclick="onCancel()">
            关闭
        </button>
    </div>
    <div class="layui-card-body">
        <table id="LAY-gp-list" lay-filter="LAY-gp-list"></table>
        @*<table class="layui-table" style="margin: 0px;">
                <colgroup>
                    <col width="150">
                    <col width="200">
                    <col width="150">
                    <col width="100">
                    <col>
                </colgroup>
                <thead>
                    <tr>
                        <th>药品编码</th>
                        <th>药品名称</th>
                        <th>规格</th>
                        <th>单价</th>
                        <th>任务量</th>
                    </tr>
                </thead>
            </table>
            <div style="height: 380px;overflow: auto;" class="profile_con">
                <table class="layui-table" style="margin: 0px;">
                    <colgroup>
                        <col width="150">
                        <col width="200">
                        <col width="150">
                        <col width="100">
                        <col>
                    </colgroup>
                    <tbody>
                        @foreach (System.Data.DataRow row in ((System.Data.DataTable)ViewData["data"]).Rows)
                        {
                            <tr>
                                <td>@row["DrugCode"]</td>
                                <td>@row["DrugName"]</td>
                                <td>@row["Specs"]</td>
                                <td>@(NCP.Core.Extensions.ConvertStringExtensions.AsDecimal(row["UnitPrice"], 0).ToString("0.######"))</td>
                                <td><input type="number" id="Code" name="Code" value="@row["TaskQTY"]" verify="required" autocomplete="off" class="layui-input"></td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>*@
    </div>
</form>
<script type="text/javascript">
    var layer;
    var admin;
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['layer', 'index', 'form', 'laydate'], function () {
        var table = layui.table
            , form = layui.form
            , $ = layui.$
            , admin = layui.admin;
        //数据绑定
        table.render({
            elem: '#LAY-gp-list'
            , url: '/GroupPurchase/GetGPList' //模拟接口
            , method: 'post'
            , height: 'full-110'
            , cols: [[
                { field: 'DrugCode', title: '药品编码', width: 160 }
                , { field: 'DrugName', title: '药品名称', minWidth: 120 }
                , { field: 'Specs', title: '规格', width: 80 }
                , { field: 'UnitPrice', title: '单价', width: 120 }
                , { field: 'TaskQTY', title: '任务量', width: 120 } 
            ]]
            , text: { none: '暂无数据' }
        });
    });

    function doSave() {
        if (valid("#dtFrm") > 0) {
            layer.alert("红色显示项必填");
            return;
        }
        var data = $("#dtFrm").serialize();
        $.ajax({
            url: '/GroupPurchase/SaveGP',
            type: 'post',
            data: data,
            success: function (res) {
                if (res.code == 0) {
                    layer.alert(res.msg, function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layui.table.reload('LAY-gp-list'); //重载表格
                        parent.layer.close(index);
                    });
                } else {
                    layer.alert(res.msg);
                }
            }
        });
    }

    function valid(fromid) {
        var not = 0;
        $(fromid).find("[verify='required']").each(function () {
            if ($(this).val() == "") {
                $(this).parent().parent().find("label").css("color", "red");
                not++;
            } else {
                $(this).parent().parent().find("label").css("color", "");
            }
        });
        return not;
    }

    function onCancel() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
</script>
